package com.baseDemo.web.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;
/**
 * 角色数据库持久类
 * @author xianwei
 *
 */

@Entity
@Table(name="t_RoleEntity")
public class RoleEntity implements Serializable{

	private static final long serialVersionUID = -5332902960384079676L;

	private String id;
	private String roleName;
	private String roleDescription;
	
	private Set<UserEntity> users = new HashSet<UserEntity>();

	private Set<AuthorityEntity> authorities = new HashSet<AuthorityEntity>();
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
	@Column(length = 50)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(length = 50)
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Column(length = 50)
	public String getRoleDescription() {
		return roleDescription;
	}

	public void setRoleDescription(String roleDescription) {
		this.roleDescription = roleDescription;
	}

	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="t_user_role",joinColumns={@JoinColumn(name="r_id")},inverseJoinColumns={@JoinColumn(name="u_id")})
	@JsonIgnore
	public Set<UserEntity> getUsers() {
		return users;
	}

	public void setUsers(Set<UserEntity> users) {
		this.users = users;
	}
	
	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="t_authority_role",joinColumns={@JoinColumn(name="r_id")},inverseJoinColumns={@JoinColumn(name="a_id")})
	@JsonIgnore
	public Set<AuthorityEntity> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<AuthorityEntity> authorities) {
		this.authorities = authorities;
	}
}
